{% extends 'layout.html' %}

{% block content %}
    <div class="luffy-container">
        <form method="post" action="?type=add">
            {% csrf_token %}
            {{ add_formset.management_form }}
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">
                    <i class="fa fa-binoculars" aria-hidden="true"></i> 待新建权限列表
                    <button class="right btn btn-primary btn-xs" style="padding: 2px 8px;margin: -3px;">
                        <i class="fa fa-save" aria-hidden="true"></i>
                        新建
                    </button>
                </div>
                <div class="panel-body" style="color: #9d9d9d;">
                    注意：路由系统中自动发现且数据库中不存在的路由。
                </div>

                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>名称</th>
                        <th>URL</th>
                        <th>别名</th>
                        <th>所属菜单</th>
                        <th>根权限</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for form in add_formset %}

                        <tr>
                            <td style="vertical-align: middle;">{{ forloop.counter }}</td>
                            <td>{{ form.title }} <span>{{ form.title.errors.0 }}</span></td>
                            <td>{{ form.url }}</td>
                            <td>{{ form.name }}</td>
                            <td>{{ form.parent }}</td>
                            <td>{{ form.menu }}</td>

                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </form>

        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <i class="fa fa-th-list" aria-hidden="true"></i> 待删除权限列表
            </div>
            <div class="panel-body" style="color: #9d9d9d;">
                注意：数据库中存在，但路由系统中不存在的路由。
            </div>

            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>名称</th>
                    <th>URL</th>
                    <th>别名</th>
                    <th>父权限</th>
                    <th>所属菜单</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for form in del_formset %}

                    <tr>
                        {{ form.id }}

                        <td style="vertical-align: middle;">{{ forloop.counter }}</td>
                        <td>{{ form.title }} <span>{{ form.title.errors.0 }}</span></td>
                        <td>{{ form.url }}</td>
                        <td>{{ form.name }}</td>
                        <td>{{ form.parent }}</td>
                        <td>{{ form.menu }}</td>
                        <td>
                            <a href="{% url 'rbac:permission_del' form.id.value %}" style="color:#d9534f;">
                                <i class="fa fa-trash-o" aria-hidden="true"></i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>

        <form method="post" action="?type=update">
            {% csrf_token %}
            {{ update_formset.management_form }}
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">
                    <i class="fa fa-sitemap" aria-hidden="true"></i> 待更新权限列表
                    <button class="right btn btn-primary btn-xs" style="padding: 2px 8px;margin: -3px;">
                        <i class="fa fa-save" aria-hidden="true"></i>
                        更新
                    </button>
                </div>
                <div class="panel-body" style="color: #9d9d9d;">
                    注意：数据库和路由系统都存在的路由。
                </div>

                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>名称</th>
                        <th>URL</th>
                        <th>别名</th>
                        <th>父权限</th>
                        <th>所属菜单</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for form in update_formset %}
                        <tr>
                            {{ form.id }}

                            <td style="vertical-align: middle;">{{ forloop.counter }}</td>
                            <td>{{ form.title }} <span>{{ form.title.errors.0 }}</span></td>
                            <td>{{ form.url }}</td>
                            <td>{{ form.name }}</td>
                            <td>{{ form.parent }}</td>
                            <td>{{ form.menu }}</td>
                            <td>
                                <a href="{% url 'rbac:permission_del' form.id.value %}" style="color:#d9534f;">
                                    <i class="fa fa-trash-o" aria-hidden="true"></i>
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </form>
    </div>
{% endblock %}